#HTML Code Cleaner
#Wes Baker

import string

from Tkinter import *

SPECIAL_CHARS = {'&lsquo;': '\'', '&rsquo;': '\'', '&sbquo;': '\'', '&ldquo;': '\"', '&rdquo;': '\"', '&bdquo;': '\"', '&lsaquo;': '<', '&rsaquo;': '>', '&nbsp;': ' ', '&lt;': '<', '&gt;': '>', '&quot;': '\"', '&ndash;': '-'}

class Cleaner:
     
    text = ""

    def __init__(self, master):
        frame = Frame(master)
        frame.pack()
        
        self.textbox = Text(frame, width=80, height=16) 
        self.textbox.pack()
        
        self.button = Button(frame, text="Clean", fg="black", command=self.text_wrapper )
        self.button.pack()

    def get_text(self):        
        self.text = self.textbox.get(1.0, END)   

    def replace_chars(self):
        for key in SPECIAL_CHARS:
            self.text = string.replace(self.text, key, SPECIAL_CHARS[key])

    def replace_text(self):
        self.textbox.delete(1.0, END)
        self.textbox.insert(1.0, self.text)
     
    def text_wrapper(self):
        self.get_text()
        self.replace_chars()
        self.replace_text()

root = Tk()

app = Cleaner(root)

root.mainloop()
